/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddThreadScreen.java
 *
 * Created on 23/04/2011, 22:13:59
 */
package implementation.gui.screens;

import javax.swing.JOptionPane;

import implementation.client.EUserParam;
import implementation.client.IUserInput;
import implementation.client.IUserInput.EUserAction;

/**
 *
 * @author Maxim
 */
public class AddThreadScreen extends javax.swing.JFrame {

	private  IUserInput _userOutputInput;
	private Object _monitor;
	
	
    /** Creates new form AddThreadScreen */
    public AddThreadScreen(IUserInput userOutputInput, Object monitor) {
    	
    	this._userOutputInput = userOutputInput;
    	this._monitor = monitor;
    	
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        logout = new javax.swing.JButton();
        profile = new javax.swing.JButton();
        back = new javax.swing.JButton();
        exit = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        threadTopic = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        threadContent = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        addPost = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel3.setFont(new java.awt.Font("Tempus Sans ITC", 0, 14));
        jLabel3.setText("Malda Community");

        logout.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11));
        logout.setText("Logout");
        logout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutActionPerformed(evt);
            }
        });

        profile.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11));
        profile.setText("Show Profile");
        profile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                profileActionPerformed(evt);
            }
        });

        back.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11));
        back.setText("Back");
        back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backActionPerformed(evt);
            }
        });

        exit.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11)); // NOI18N
        exit.setText("Exit");
        exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11));
        jLabel1.setText("Thread Topic:");

        threadTopic.setFont(new java.awt.Font("Times New Roman", 0, 12));

        threadContent.setColumns(20);
        threadContent.setFont(new java.awt.Font("Courier New", 0, 12));
        threadContent.setRows(5);
        jScrollPane1.setViewportView(threadContent);

        jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11));
        jLabel2.setText("Content:");

        addPost.setFont(new java.awt.Font("Tempus Sans ITC", 0, 11)); // NOI18N
        addPost.setText("Publish");
        addPost.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPostActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(361, Short.MAX_VALUE)
                .addComponent(addPost)
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(12, 12, 12)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(threadTopic)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE))
                    .addContainerGap(13, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(207, Short.MAX_VALUE)
                .addComponent(addPost)
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(5, 5, 5)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(threadTopic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(47, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(back)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 315, Short.MAX_VALUE)
                                .addComponent(exit)
                                .addGap(28, 28, 28))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
                                .addComponent(logout)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(profile)))
                        .addGap(28, 28, 28))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(profile)
                        .addComponent(logout))
                    .addComponent(jLabel3))
                .addGap(32, 32, 32)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(back)
                    .addComponent(exit))
                .addGap(24, 24, 24))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void logoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutActionPerformed
        
        this._userOutputInput.setSelectedAction(EUserAction.ELogout);
        
        synchronized(this._monitor){
            this._monitor.notify();
        }
        this.dispose();
        
    }//GEN-LAST:event_logoutActionPerformed

    private void profileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profileActionPerformed
        
        this._userOutputInput.setSelectedAction(EUserAction.EProfile);
        
        synchronized(this._monitor){
            this._monitor.notify();
        }
        this.dispose();
}//GEN-LAST:event_profileActionPerformed

    private void backActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backActionPerformed
        
        
        this._userOutputInput.setSelectedAction(EUserAction.EBack);
        
        synchronized(this._monitor){
            this._monitor.notify();
        }
        this.dispose();
}//GEN-LAST:event_backActionPerformed

    private void exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitActionPerformed
        
        this._userOutputInput.setSelectedAction(EUserAction.EExit);
        
        synchronized(this._monitor){
            this._monitor.notify();
        }
        this.dispose();
}//GEN-LAST:event_exitActionPerformed

    private void addPostActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPostActionPerformed
        
        
        if(this.threadTopic.getText().length() == 0){
            JOptionPane.showMessageDialog(null, "The thread topic cannot be empty ", null, JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(this.threadContent.getText().length() == 0){
            JOptionPane.showMessageDialog(null, "The thread content cannot be empty ", null, JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        this._userOutputInput.setSelectedAction(EUserAction.EAddThread);
        this._userOutputInput.setParam(EUserParam.ETopic, this.threadTopic.getText());
        this._userOutputInput.setParam(EUserParam.EContent, this.threadContent.getText());
        
        
        
        synchronized(this._monitor){
            this._monitor.notify();
        }
        this.dispose();
        
        
    }//GEN-LAST:event_addPostActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addPost;
    private javax.swing.JButton back;
    private javax.swing.JButton exit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton logout;
    private javax.swing.JButton profile;
    private javax.swing.JTextArea threadContent;
    private javax.swing.JTextField threadTopic;
    // End of variables declaration//GEN-END:variables
}
